/*
 * Copyright (C) 2015 Baidu, Inc. All Rights Reserved.
 */
package net.oschina.zenglingfan.idea.plugin.example.action;

import com.google.common.collect.Lists;
import com.intellij.openapi.actionSystem.AnAction;
import com.intellij.openapi.actionSystem.AnActionEvent;
import com.intellij.openapi.actionSystem.DataKeys;
import com.intellij.openapi.diagnostic.Logger;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.vcs.actions.VcsContext;
import com.intellij.openapi.vcs.actions.VcsContextFactory;
import com.intellij.openapi.vcs.changes.ChangeListManager;

import net.oschina.zenglingfan.idea.plugin.example.ui.ExampleDialog;

/**
 * 示例 1
 */
public class Example1 extends AnAction {
    private static final Logger LOG = Logger.getInstance(Example1.class);

    public void actionPerformed(AnActionEvent e) {
        // DataKeys 事件触发是的上下文变量
        Project project = e.getData(DataKeys.PROJECT);

        // VCS 相关上下文
        VcsContext vcsContext = VcsContextFactory.SERVICE.getInstance().createContextOn(e);
        ChangeListManager changeListManager = ChangeListManager.getInstance(e.getProject());

        // 显示当前选中的 changes
        ExampleDialog dialog = new ExampleDialog(project,  changeListManager.getChangeListsCopy(),
                Lists.newArrayList(vcsContext.getSelectedChanges()));
        dialog.show();
    }
}
